package ywh.player.av {
	
	/**
	 * 声音管理类
	 * @author WilliWHYang
	 */
	public class AudioManager
	{
		private var _media:IAudioHandle;
		private var _volume:Number;
		private var _isMute:Boolean;
		
		public function AudioManager(media:IAudioHandle)
		{
			_isMute = false;
			setMedia(media);
		}
		
		public function setMedia(media:IAudioHandle):void
		{
			_media = media;
			volume = _media.volume;
		}
		
		/**
		 * 更新媒体音量;主要在媒体内容发生变化时，某些情况下音量发生变化后
		 */
		public function reset():void
		{
			_media.volume=_isMute ? 0 : _volume;
		}
		
		/* INTERFACE player.IAudio */ /**
		 * 获取当前音量;
		 */
		public function get volume():Number
		{
			return _volume;
		}
		
		/**
		 * 设置音量;
		 */
		public function set volume(value:Number):void
		{
			value = value < 0 ? 0 : (value > 1 ? 1 : value);
			_volume = value;
			_media.volume=_isMute ? 0 : _volume;
		}
		
		/**
		 * 获取静音状态;
		 */
		public function get isMute():Boolean
		{
			return _isMute;
		}
		
		/**
		 * 静音
		 */
		public function mute():void
		{
			_isMute = true;
			_media.volume=0;
		}
		
		/**
		 * 取消静音
		 */
		public function unmute():void
		{
			_isMute = false;
			_media.volume=_volume;
		}
	
	}

}